/* SPDX-License-Identifier: GPL-2.0
 * rtc.h - rtc head file
 *
 * Copyright (C) 2016-2018, LomboTech Co.Ltd.
 * Author: lomboswer <lomboswer@lombotech.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef __LOMBO_RTC_H___
#define __LOMBO_RTC_H___

#if	defined(CONFIG_ARCH_LOMBO_N9V1_FPGA) || \
	defined(CONFIG_ARCH_LOMBO_N7V3_FPGA) || \
	defined(CONFIG_ARCH_LOMBO_N7V5_FPGA) || \
	defined(CONFIG_ARCH_LOMBO_N5V1_FPGA)
#define FPGA
#endif

#define ENABLE			1
#define DISABLE			0

/* RTC CLK source */
#define CLK_SRC_LFEOSC		1
#define CLK_SRC_RCOSC		0
#define CLK_SRC1                1
#define CLK_SRC0                0

#if defined FPGA
#define RTC_SRC         CLK_SRC_RCOSC
#else
#define RTC_SRC         CLK_SRC_LFEOSC
#endif

#if defined(CONFIG_ARCH_LOMBO_N7V1)
#include "csp/n7v1/rtc_csp.h"
#define RTC_NAME "n7v1-rtc"
#elif defined(CONFIG_ARCH_LOMBO_N7V3)
#include "csp/n7v3/rtc_csp.h"
#define RTC_NAME "n7v3-rtc"
#elif defined(CONFIG_ARCH_LOMBO_N7V5)
#include "csp/n7v5/rtc_csp.h"
#define RTC_NAME "n7v5-rtc"
#elif defined(CONFIG_ARCH_LOMBO_N5V1)
#include "csp/n5v1/rtc_csp.h"
#define RTC_NAME "n5v1-rtc"
#elif defined(CONFIG_ARCH_LOMBO_N9V1)
#include "csp/n9v1/rtc_csp.h"
#define RTC_NAME "n9v1-rtc"
#elif defined(CONFIG_ARCH_LOMBO_N9V3)
#include "csp/n9v3/rtc_csp.h"
#define RTC_NAME "n9v3-rtc"
#endif

/**
 * struct lombo_rtc - Runtime info holder for RTC and RTC power driver.
 * @irq_no: Irq No.
 * @power_irq_pending: Power irq pending status.
 * @rtc: Pointer to RTC device.
 */
struct lombo_rtc {
	struct rtc_device *rtc_dev;
	struct device *dev;
	void __iomem *base;
	u32 irq_no;
	u32 alarm_int_pending;
	u32 wake_en;
	const struct lombo_rtc_data *data;
};

struct lombo_rtc_data {
	int (*low_volt_detect)(struct lombo_rtc *);
	int (*low_volt_int_handler)(struct lombo_rtc *);
	int (*core_config)(struct lombo_rtc *);
	int (*int_enable)(struct lombo_rtc *, u32);
	int (*clr_all_pending)(struct lombo_rtc *);
	int (*clk_src_init)(struct lombo_rtc *);
};

#endif
